package com.rental.user.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.rental.common.result.AjaxResult;
import com.rental.model.dto.UserInfoDto;

import com.rental.model.entity.user.UserInfo;
import com.rental.model.form.user.GetRecordForm;
import com.rental.model.form.user.PhoneAndCodeForm;
import com.rental.model.vo.user.RecordVo;
import com.rental.user.service.IUserInfoService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/userInfo")
public class UserInfoController {
    @Autowired
    private IUserInfoService userInfoService;

    /**
     * 获取登录信息
     *
     * @param token
     * @return
     */
    @Operation(summary = "获取登录信息")
    @GetMapping("/getUserInfo")
    AjaxResult<UserInfo> getUserInfo(@RequestParam("token") String token) {
        return AjaxResult.success(userInfoService.getUserInfo(token));
    }

    /**
     * 发送验证码
     *
     * @param phoneAndCodeForm 手机号
     * @return 验证码
     */
    @Operation(summary = "发送验证码")
    @PostMapping("/sendCode")
    public AjaxResult<String> sendCode(@RequestBody PhoneAndCodeForm phoneAndCodeForm) {
        String token = userInfoService.sendCode(phoneAndCodeForm);
        return AjaxResult.success(token);
    }

    /**
     * 登录
     */
    @Operation(summary = "登录")
    @PostMapping("/login")
    public AjaxResult<String> login(@RequestBody PhoneAndCodeForm phoneAndCodeForm) {
        String login = userInfoService.login(phoneAndCodeForm);
        return AjaxResult.success(login);
    }

    /**
     * 获取浏览记录
     *
     * @param getRecordForm 请求表单
     * @return 浏览记录
     */
    @Operation(summary = "获取浏览记录")
    @PostMapping("/getBrowseRecord")
    public AjaxResult<RecordVo> getBrowseRecord(@RequestBody GetRecordForm getRecordForm) {
        return AjaxResult.success(userInfoService.getBrowseRecord(getRecordForm));
    }

    /**
     * 获取收藏信息
     *
     * @param getRecordForm 请求表单
     * @return 收藏信息
     */
    @Operation(summary = "获取收藏信息")
    @PostMapping("/getCollectInfo")
    public AjaxResult<RecordVo> getCollectInfo(@RequestBody GetRecordForm getRecordForm) {
        return AjaxResult.success(userInfoService.getCollectInfo(getRecordForm));
    }

    /**
     * 根据id查询用户信息
     *
     * @param id
     * @return
     */
    @Operation(summary = "根据id查询用户信息")
    @GetMapping("/getUserById")
    AjaxResult<UserInfo> getUserById(@RequestParam("id") Long id) {
        return AjaxResult.success(userInfoService.getById(id));
    }

    @GetMapping("/getUserInfoById")
    public AjaxResult<UserInfo> getUserInfoById(@RequestParam("id") Long id) {
        return AjaxResult.success(userInfoService.getById(id));
    }

    /**
     * 根据id修改用户信息
     *
     * @param userInfo
     * @return
     */

    @Operation(summary = "根据id修改用户信息")
    @PostMapping("/updateUserInfoById")
    public AjaxResult<Boolean> updateUserInfoById(@RequestBody UserInfo userInfo) {
        return AjaxResult.success(userInfoService.updateById(userInfo));
    }

    /**
     * 查询所有用户信息
     *
     * @return
     */
    @Operation(summary = "查询所有用户信息")
    @GetMapping("/getAllUserInfo")
    public AjaxResult<List<UserInfo>> getAllUserInfo() {
        return AjaxResult.success(userInfoService.list());
    }

    /**
     * 获取用户发布页面
     *
     * @param getRecordForm 请求表单
     * @return 发布页面
     */
    @Operation(summary = "获取用户发布页面")
    @PostMapping("/getPublish")
    public AjaxResult<RecordVo> getPublish(@RequestBody GetRecordForm getRecordForm) {
        return AjaxResult.success(userInfoService.getPublish(getRecordForm));
    }

    /**
     * 统计平台拉黑的中介数
     *
     * @return 统计结果
     */
    @Operation(summary = "统计平台拉黑的中介数")
    @GetMapping("/countBannedUser")
    public AjaxResult<Long> countBannedUser() {
        return AjaxResult.success(userInfoService.countBannedUser());
    }
}
